var app = getApp()
// pages/list/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    contents:'',
    defult: 10,
    isPage: 1,
    navId: "",
    isEmpty: true,
    requestLoading:false,
    requestLoadingComplete: true  //“没有数据”的变量，默认false，隐藏  
  },

  //传递数据到发送页面
  onBatch: function (e) {
    var data = e.currentTarget.dataset;
    wx.navigateTo({
      url: '/pages/batch/batch?data=' + JSON.stringify(data) + "&class=" + 0,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showNavigationBarLoading();
    var getApiContUrl = app.globalData.smsbaoApi + "/batch/sapi/get_sms_content";
    var nav = JSON.parse(options.nav);
    this.setData({
      navName: nav,
      navId: nav.id,
    })
    //请求数据的参数
    var parameter = {
      cid: nav.id,
      num: this.data.defult,
      page: this.data.isPage,
      isChoice: 0
    };
    this.getApiContent(getApiContUrl, parameter);
  },
  getApiContent: function (url, parameter) {
    let that = this;
    wx.request({
      url: url,
      data: parameter,
      method: "post",
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.code == '200') {
          if (!that.data.isEmpty) {
            if (res.data.code == '200' && res.data.data == undefined || res.data.data == '') {
              that.setData({
                requestLoadingComplete: false,
                requestLoading: true
              })
              wx.hideNavigationBarLoading();
              wx.stopPullDownRefresh();
              return false;
            } else {
             var updata = res.data.data;
             var data = that.data.contents.concat(updata);
             that.setData({
               contents: data
             })           
            }
          } else {
            var data = res.data.data;
            that.data.isEmpty = false
            that.setData({
              contents: data
            })
          }
          
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
        } else {
          return false;
        }
      },
      fail: function (error) {
        console.log(error)
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function (e) {
    wx.setNavigationBarTitle({
      title: this.data.navName.name
    })
  },
  //上拉加载
  onReachBottom: function (event) {
    var getApiContUrl = app.globalData.smsbaoApi + "/batch/sapi/get_sms_content";
    var isPage = this.data.isPage++;
    var parameter = {
      cid: this.data.navId,
      num: this.data.defult,
      page: isPage,
      isChoice: 0
    };
    this.getApiContent(getApiContUrl, parameter)
    wx.showNavigationBarLoading();
  }
})
